// pages/index/serve.js
const http = require('../../../utils/http.js'); //相对路径
Page({
  /**
   * 页面的初始数据
   */
  data: {
    qianmingmark: false,
    show: true,
    disabled: true,
    // date: {
    //   date: '',
    //   startDate: '2019-01-01 12:37',
    //   endDate: '2019-03-12 12:38',
    //   placeholder: '请选择时间',
    // },
    // date1: {
    //   date: '',
    //   startDate: '2019-01-01 12:37',
    //   endDate: '2019-03-12 12:38',
    //   placeholder: '请选择时间',
    // },

    workId:'',
    workNumber:'',
    detailData:'',
    date:"",
    date1:"",
    array1: ['美国', '中国', '巴西', '日本'],
    staffData:'',//服务顾问
    professionCate:'',//业务分类
    professionindex:0,
    carCate:'',//车辆分类
    carCateindex:0,
    provider:'',//供应商数据
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      workId:options.workId,
      workNumber:options.workNumber
    })
    this.getBase()
    this.getData()
  },
 // 获取基础数据
 getBase(){
  http.postRequest('/mini/v1/work/base_data', {
    shop_app_id: wx.getAccountInfoSync().miniProgram.appId
  }, res => {
    var carCate=[]
    for(var i in res.data.car_cate){
      carCate.push(res.data.car_cate[i].name)
    }
    var professionCate=[]
    for(var i in res.data.profession_cate){
      professionCate.push(res.data.profession_cate[i].name)
    }
   this.setData({
    staffData:res.data.staff_data,
    professionCate:professionCate,
    carCate:carCate,
    provider:res.data.provider
   })
   
  })
},
//获取工单详情数据
  getData(){
    http.postRequest('/mini/v1/work/info', {
      shop_app_id: wx.getAccountInfoSync().miniProgram.appId,
      work_id: this.data.workId,
      work_number: this.data.workNumber
    }, res => {
      this.setData({
        detailData:res.data,
        date:http.transTime(res.data.enter_time),
        date1:http.transTime(res.data.exit_time),
        carCateindex:res.data.car.car_category_id,
        professionindex:res.data.profession_cate_id
      })
      // console.log(http.transTime(res.data.enter_time));
      // console.log(http.transTime(res.data.exit_time));
      // console.log(this.data.date);
      // console.log(this.data.date1);
      
      
      
    })
  },
  navbind(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      navindex: index
    })
  },
  onPickerChange(e) {
    let date = this.data.date
    date.dateString = e.detail.dateString
    this.setData({
      date: date
    })
  },
  onPickerChange1(e) {
    let date1 = this.data.date1
    date1.dateString = e.detail.dateString
    this.setData({
      date1: date1
    })
  },
 //车辆分类
 bindPickerChange: function (e) {
  this.setData({
    carCateindex: e.detail.value
  })
},
//业务分类
bindPickerChange1: function (e) {
  this.setData({
    professionindex: e.detail.value
  })
},
  btn(e) {
    let name = e.currentTarget.dataset.name;
    let disabled = this.data.disabled
    if(name =='wangon') {
      wx.navigateTo({
        url: '/pages/index/work/quality?name='+ this.data.pageName
      })
    } else if(name == 'genduo') {
      wx.showActionSheet({
        itemList: ['签名', '质检结果', '再来一单',''],
        success: function (res) {
          if(res.tapIndex == 0) {
            wx.navigateTo({
              url: '/pages/sign/sign'
            })
          }
          if(res.tapIndex == 1) {
            wx.navigateTo({
              url: '/pages/index/work/quality'
            })
          }
          if(res.tapIndex == 2) {
            wx.navigateTo({
              url: '/pages/openOrder/wash/wash'
            })
          }
        }
      })
    } else if(name == 'xiugai') {
      if(disabled) {
        this.setData({
          disabled: false
        })
        wx.showToast({
          title: '数据可编辑',
          icon: ''
        })
      } else {
        this.setData({
          disabled: true
        })
        wx.showToast({
          title: '数据不可编辑',
          icon: ''
        })
      }
    } 
  },
  show() {
    this.setData({
      show: false
    })
  },
  hide() {
    this.setData({
      show: true
    })
  },
  shouhuanmalod() {
    wx.navigateTo({
      url: '/pages/index/sell/shouzhi'
    })
  },
  copyText() {
    const text = this.data.copyText
    wx.setClipboardData({
      data: text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  }
})